package com.yc.yyds.dao;

import com.yc.yyds.util.DBHelper;

import java.util.List;
import java.util.Map;

public class CommentsDao {
    //查找电影所有评论评论评论
    public List<Map<String,Object>> queryComment(String movieid){
        String sql ="select id ,c.userid,us.username,us.image ,content,c.creat_time, pid,u.username pname ,dingjiid,movieid  from user us " +
                "INNER JOIN  comments c on us.userid = c.userid " +
                "LEFT JOIN  user u on c.pid=u.userid where movieid= ?";
        return DBHelper.selectListMap(sql,movieid);
    }
    //保存评论
    public void saveComment(String userid,String movieid,String content,String pid,String dingjiid){
        String sql = " insert into comments(userid,movieid,content,pid,dingjiid) values (?,?,?,?,?)";
        DBHelper.update(sql,userid,movieid,content,pid,dingjiid);
    }
    //删除评论
    public void delete(String id){
        String sql = " delete from comments where id = ? or dingjiid=?";
        DBHelper.update(sql,id,id);
    }
    public Map<String, Object> moviedesc(String movieid){
        String sql = "select * from movie where movieid = ?";
        return DBHelper.selectOneMap(sql,movieid);
    }

}
